//
//  ZJBinding.swift
//  Pods-ZJSwiftKit_Example
//
//  Created by 万孟超 on 2023/10/9.
//

import Foundation

@dynamicMemberLookup
public struct ZJBinding<ZJBind> {
    public var object: ZJBind
    
    /// 初始化包装器
    /// - Parameter object: 包装的实例
    public init(_ object: ZJBind) {
        self.object = object
    }
    
    /// Automatically synthesized binder for a key path between the reactive
    /// base and one of its properties
    public subscript<Property>(dynamicMember keyPath: ReferenceWritableKeyPath<ZJBind, Property>) -> ((Property) -> ZJChained<ZJBind>) where ZJBind: AnyObject {
        let subject = object
        return {
            subject[keyPath: keyPath] = $0
            return ZJChained(subject)
        }
    }
}

/// A type that has reactive extensions.
public protocol ZJBindProtocol { }

extension ZJBindProtocol {
    
    /// ZJPrefix extensions.
    public static var zjbd: ZJBinding<Self>.Type {
        get{ ZJBinding.self }
        set{ }
    }
    
    /// ZJPrefix extensions.
    public var zjbd: ZJBinding<Self> {
        get{ ZJBinding.init(self) }
        set {}
    }
}

extension NSObject: ZJBindProtocol { }
